﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AdminModel;

namespace Wine.Controllers
{
    public class HomeController : Controller
    {
        Wine.Logic.logic logic = new Logic.logic();
        //
        // GET: /Home/
        /// <summary>
        /// 首页(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View(logic.GetGoodsMessage().ToList());
        }
        /// <summary>
        /// 公告信息显示页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Notice(int id)
        {
            return View(logic.GetNotice().Where(p=>p.NoticeID==id).FirstOrDefault());
        }
        /// <summary>
        /// 公告信息显示
        /// </summary>
        /// <returns></returns>
        public ActionResult GetNotice()
        {
        
            return Json(logic.GetNotice().ToList());
        }
        /// <summary>
        /// 根据id显示详细的公告信息显示
        /// </summary>
        /// <returns></returns>
        public ActionResult GetNotice1()
        {
            Session["date"] = DateTime.Now.ToString();
            return View(logic.GetNotice().ToList());
        }
        /// <summary>
        /// 酒帝独家(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult Dujia()
        {
            return View();
        }
        /// <summary>
        /// 葡萄酒馆(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult PuTao()
        {
            return View(logic.GetGoodsMessage().ToList());
        }
        /// <summary>
        /// 洋酒馆(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult YangJiuGuan()
        {
            return View(logic.GetGoodsMessage().ToList());
        }
        /// <summary>
        /// 家入购物车
        /// </summary>
        /// <returns></returns>
        public ActionResult JiaRuGouWuChe(int id)
        {
            ViewBag.goodtypee = logic.GetGoodsType();
            return View(logic.GetGoodsMessage().Where(p => p.GoodsID == id).FirstOrDefault());
        }
        /// <summary>
        /// 购物车(完成)(根据商品编号显示)
        /// </summary>
        /// <returns></returns>
        public ActionResult GouWu(int id=4)
        {
          
            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.area = logic.GetArea();
            ViewBag.goods = logic.GetGoodsMessage();
            ViewBag.goodtypee = logic.GetGoodsType();
            return View(logic.GetInt().Where(p => p.IndentID == id).ToList());
        }
        /// <summary>
        /// 订单界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult Dingdan(int id=4)
        {
            Session["date"] = DateTime.Now.ToString();
            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.area = logic.GetArea();
            ViewBag.goods = logic.GetGoodsMessage();
            ViewBag.goodtypee = logic.GetGoodsType();
            return View(logic.GetInt().Where(p => p.IndentID == id).ToList());
        }
        /// <summary>
        /// 购买界面(完成)结算界面支付
        /// </summary>
        /// <returns></returns>
        public ActionResult GouMai(double Price ,int id)
        {
            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.area = logic.GetArea();
            ViewBag.goods = logic.GetGoodsMessage();
            ViewBag.goodtypee = logic.GetGoodsType();
            ViewBag.price = Price;
            ViewBag.id = id;
            return View(logic.GetInt());
        }
        /// <summary>
        /// 结算界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult JieSuan(int id = 4)
        {
            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.area = logic.GetArea();
            ViewBag.goods = logic.GetGoodsMessage();
            ViewBag.goodtypee = logic.GetGoodsType();
            return View(logic.GetInt().Where(p => p.IndentID == id).ToList());
        }
        /// <summary>
        /// 支付界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult ZhiFu()
        {
            return View();
        }
        /// <summary>
        /// 付款界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult FuKuan(double Price, int id)
        {

            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.area = logic.GetArea();
            ViewBag.goods = logic.GetGoodsMessage();
            ViewBag.goodtypee = logic.GetGoodsType();
            ViewBag.price = Price;
            ViewBag.id = id;
            return View(logic.GetInt());
        }





        /// <summary>
        /// 收藏(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult ShouCang()
        {
            return View();
        }
        /// <summary>
        /// 提交(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult Tijao()
        {
            return View();
        }
        /// <summary>
        /// 退货界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult TuiHuo()
        {
            ViewBag.users = logic.GetUsers();
            ViewBag.indent = logic.GetIndent();
            return View(logic.GetRenturned().ToList());
        }
        /// <summary>
        /// 用户信息(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult UserXin()
        {
            return View();
        }
        /// <summary>
        /// 基本信息(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult JiBenXinXi()
        {

            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.usersrelo = logic.GetUsersRole();
            ViewBag.indent = logic.GetIndent();
            return View(logic.GetInt().ToList());
        }
        /// <summary>
        /// 账户安全(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult ZhangHuAnQuan()
        {
            return View();
        }
        /// <summary>
        /// 登录界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginJiu()
        {
            ViewBag.users = logic.GetUsers();
            ViewBag.usersrole = logic.GetUsersRole();
            return View();
        }
        public ActionResult deng(string UsersName, string UsersPwd)
        {
            try
            {

                if (logic.GetUsers().Where(p => p.UsersName == UsersName && p.UsersPwd == Convert.ToInt32(UsersPwd)).ToList().Count > 0)
                {
                    return Content("<script>alert('登陆成功！');location.href='/Home/Index'</script>");
                }
            }
            catch
            {
                return Content("<script>alert('登录失败！！');location.href='/Home/Index'</script>");
            }
            return Content("<script>alert('登录异常！！');location.href='/Home/Index'</script>");
        }
        /// <summary>
        /// 注册界面(完成)
        /// </summary>
        /// <returns></returns>
        public ActionResult AddLogin()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Adduserssed(Users u)
        {
            try
            {
                u.UsersName = u.UsersTel.ToString();
                u.UsersRoleID = 1;
                if (logic.AddUsers1(u) > 0)
                {
                    return Content("<script>alert('添加成功！');location.href='/Home/Index'</script>");
                }
            }
            catch
            {
                return Content("<script>alert('添加失败！');location.href='/Home/Index'</script>");
            }
            return Content("<script>alert('添加异常！');location.href='/Home/Index'</script>");
        }

    }
}
